import { createRouter, createWebHashHistory } from 'vue-router'

// 导入公共布局组件（一级路由）
const Layout = () => import('@/views/layout')
// 首页
const Home = () => import('@/views/home')
// 商品详情
const GoodDetail = () => import('@/views/good')
// 登录
const Login = () => import('@/views/login')
// 购物车
const Cart = () => import('@/views/cart')
// 订单
const Settlement = () => import('@/views/member/order/index.vue')
const Pay = () => import('@/views/member/pay/index')
const PayResult = () => import('@/views/member/pay/result')

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      { path: '/', component: Home },
      { path: '/detail/:id', component: GoodDetail },
      { path: '/cart', component: Cart },
      {
        path: '/order',
        component: Settlement
      },
      { path: '/pay', component: Pay },
      { path: '/pay/callback', component: PayResult }
    ]
  },
  {
    path: '/login',
    component: Login
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  // 每次路由跳转重置滚动条
  // vue2 { x: 0, y: 0 }
  scrollBehavior () {
    return { left: 0, top: 0 }
  }
})

export default router
